import sim, sim_items, main
from util import *
import random

class CorrodedPrefix(sim_items.Prefix):
    """
    "corroded" prefix gives affected weapon a small damage malus
    """
    def __init__(self):
        super(CorrodedPrefix, self).__init__(
            "corroded", # name
            # description: (gets tacked onto item description)
            "Rusty, worn, and older than you, this %(wearable)s "
            "has seen better days."
        )

    def initialize(self, wearable):
        if not isinstance(wearable, sim_items.Weapon):
            raise ValueError('Tried to apply %r to non-weapon item: %r' % (self,
                wearable))

        super(CorrodedPrefix, self).initialize(wearable)

        multiplier = 0.10 + 0.1*random.random()
        self.dmgMod = multiplier * wearable.damage

        wearable.damage -= self.dmgMod

    def remove(self, wearable):
        super(CorrodedPrefix, self).remove(wearable)
        wearable.damage += self.dmgMod

#========================================
thingClass = CorrodedPrefix

